<?php require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('infolist');
$starttimer = microtime(true);
$cid = isset($cid) ? $cid : '';
$checkPagenum = isset($checkPagenum) ? $checkPagenum : $cfg_pagenum; 
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>列表信息管理 </title>
<link href="templates/css/style.css" rel="stylesheet" type="text/css" />
<link href="templates/css/pagination.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="templates/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/layindex.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/common.js"></script>
<script type="text/javascript" src="templates/js/forms.func.js"></script>
</head>

<body class="mainbody">
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
  <a href="home.php" class="home"><i></i><span>首页</span></a>
  <i class="arrow"></i>
  <span>列表信息管理</span>
  <a href="javascript:location.reload();" class="reload">刷新</a>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"></a>
      <div class="l-list">
        <ul class="icon-list">
		 <?php if(IsModel('infolist','add',1)!=false) echo'<li><a class="add" href="infolist_add.php?cid='.$cid.'"><i></i><span>新增</span></a></li>'; ?>
          <li><a class="all" href="javascript:;" onclick="checkAll(this);"><i></i><span>全选</span></a></li>
		 <?php if(IsModel('infolist','del',1)!=false) echo'<li><a href="javascript:SubUrlParam(\'infolist_save.php?action=delall\')"  onclick="return ConfDelAll(0);" class="del"><i></i><span>删除</span></a></li>';?>
        
        </ul> 
		<div class="rule-single-select">
		<select name="cid" onchange="func('cid')" id="cid">
			<?php CategoryMyType('1'); ?>
		</select>
         </div>
		  <div class="rule-single-select">
     <select name="flag" onchange="func('flag')" id="flag">
		<option selected="selected" value="all">所有属性</option>
		<option <?php if(@$flag=='notcheck') echo 'selected="selected"';?> value="notcheck">未审核</option>
		<option <?php if(@$flag=='ischeck') echo 'selected="selected"';?> value="ischeck">已审核</option>
		<?php
			$dosql->Execute("SELECT * FROM `#@__infoflag` ORDER BY orderid ASC");
			while($row = $dosql->GetArray())
			{	if(@$flag==$row['flag']) $select='selected="selected"';else $select=''; 
				echo '<option '.$select.' value="'.$row['flag'].'">'.$row['flagname'].'['.$row['flag'].']</option>';
			}
			?>
	</select>
          </div>
      </div>
      <div class="r-list">
	  <form name="form3" id="form3" method="post" action="infolist.php">
        <input name="keyword" type="text" id="keyword" class="keyword" />
        <input  class="btn-search" type="submit" value="搜索" style="cursor:pointer;">
		</form>
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->
<form method="post" action="" id="form">
<!--列表-->
<div class="table-container">

  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
    <tr>
		<th width="5%">选择</th>
		<th width="5%">ID</th>
		<th width="30%">标题</th>
		<th width="15%">栏目</th>
		<th width="15%">更新时间</th>
		<th width="10%">发布人</th>
		<th width="5%">点击</th>
		<th width="10%" >操作</th>
    </tr>
  
  	<?php


	//权限验证
	if($cfg_adminlevel != 1)
	{
		//初始化参数
		$catgoryListPriv   = '';
		$catgoryUpdatePriv = array();
		$catgoryDelPriv    = array();
		$catgoryAuditPriv    = array();

		$dosql->Execute("SELECT * FROM `#@__adminprivacy` WHERE `groupid`=".$cfg_adminlevel." AND `model`='category' AND `action`<>'add'");
		while($row = $dosql->GetArray())
		{
			//查看权限
			if($row['action'] == 'list')
				$catgoryListPriv .= $row['classid'].',';

			//修改权限
			if($row['action'] == 'update')
				$catgoryUpdatePriv[] = $row['classid'];

			//删除权限
			if($row['action'] == 'del')
				$catgoryDelPriv[]    = $row['classid'];
			
			//审核权限
			if($row['action'] == 'Audit')
				$catgoryAuditPriv[]    = $row['classid'];

		}

		$catgoryListPriv = trim($catgoryListPriv,',');
	}
	
	$sql = "SELECT * FROM `#@__infolist` WHERE siteid='$cfg_siteid' AND delstate=''";

	if(!empty($catgoryListPriv)) $sql .= " AND classid IN ($catgoryListPriv)";

	if(!empty($cid))     $sql .= " AND (classid=$cid OR parentstr Like '%,$cid,%')";

	if(!empty($keyword)) $sql .= " AND title LIKE '%$keyword%'";

	if(!empty($flag))
	{
		if($flag == 'all')
			$sql .= 'AND id<>0';
		else if($flag == 'notcheck')
			$sql .= "AND checkinfo='false'";
		else if($flag == 'ischeck')
			$sql .= "AND checkinfo='true'";
		else if($flag == 'author')
			$sql .= "AND author='".$_SESSION['admin']."'";
		else
		{
			$dosql->Execute("SELECT `flag` FROM `#@__infoflag`");
			while($row = $dosql->GetArray())
			{
				if($row['flag'] == $flag)
				{
					$sql .= "AND `flag` LIKE '%$flag%'";
				}
			}
		}
	}
	$dopage->GetPage($sql,$checkPagenum,'DESC');
	while($row = $dosql->GetArray())
	{	


			//标题名称
		$title  = '<span class="title" style="color:'.$row['colorval'].';font-weight:'.$row['boldval'].'">'.$row['title'];
		$title .= '<span class="titflag">';

		//信息属性
		$flagarr = explode(',',$row['flag']);
		$flagnum = count($flagarr);
		for($i=0; $i<$flagnum; $i++)
		{
			$r = $dosql->GetOne("SELECT `flagname` FROM `#@__infoflag` WHERE `flag`='".$flagarr[$i]."'");

			if(isset($r['flagname']))
			{
				$title .= $r['flagname'].'&nbsp;';
			}
		}

		$title .= '</span>';
		
		//获取类型名称
		$r = $dosql->GetOne("SELECT classname FROM `#@__infoclass` WHERE id=".$row['classid']);

		if(isset($r['classname']))
			$classname = $r['classname'].' ['.$row['classid'].']';
		else
			$classname = '<span class="red">分类已删 ['.$row['classid'].']</span>';

		//缩略图标
		if($row['picurl'] != '')
		{
			$title .= '&nbsp;<span class="titpic"><i title="包含缩略图"></i></span>';
		}


		$title .= '</span>';
			//获取审核状态
		switch($row['checkinfo'])
		{
			case 'true':
				$checkinfo = '已审';
				break;
			case 'false':
				$checkinfo = '未审';
				break;
			default:
				$checkinfo = '没有获取到参数';
		}


		//修改权限
		if($cfg_adminlevel != 1)
		{
			if(in_array($row['classid'], $catgoryUpdatePriv))
				$updateStr = '<a href="infolist_update.php?cid='.$row['classid'].'&id='.$row['id'].'">修改</a>';
			else
				$updateStr = '修改';
		}
		else
		{
			$updateStr = '<a href="infolist_update.php?cid='.$row['classid'].'&id='.$row['id'].'">修改</a>';
		}


		//删除权限
		if($cfg_adminlevel != 1)
		{
			if(in_array($row['classid'], $catgoryDelPriv))
				$delStr = '<a href="infolist_save.php?action=del&id='.$row['id'].'&title='.$row['title'].'" onclick="return ConfDel(2);">删除</a>';
			else
				$delStr = '删除';
		}
		else
		{
			$delStr = '<a href="infolist_save.php?action=del&id='.$row['id'].'" onclick="return ConfDel(2);">删除</a>';
		}


		//审核权限
		if($cfg_adminlevel != 1)
		{
			if(in_array($row['classid'], $catgoryAuditPriv))
				$checkStr = '<a href="javascript:;" title="点击进行审核与未审操作" onclick="CheckInfolist('.$row['id'].',\''.$checkinfo.'\',\'infolist_save.php\')">'.$checkinfo.'</a>';
			else
				$checkStr = $checkinfo;
		}
		else
		{
			$checkStr = '<a href="javascript:;" title="点击进行审核与未审操作" onclick="CheckInfolist('.$row['id'].',\''.$checkinfo.'\',\'infolist_save.php\')">'.$checkinfo.'</a>';
		}
	?>
	 <tr>
		<td align="center"><span class="checkall" style="vertical-align:middle;"><input type="checkbox" name="checkid[]" value="<?php echo $row['id']; ?>" /></span></td>
     	<td align="center"><?php echo $row['id']; ?></td>
		<td><?php echo $title; ?></td>
		<td align="center"><?php echo $classname; ?></td>
		<td align="center" class="number"><?php echo GetDateTime($row['posttime']); ?></td>
		<td align="center"><?php echo $row['author']; ?></td>
		<td align="center"><?php echo $row['hits']; ?></td>
		<td align="center"><span id="check<?php echo $row['id']; ?>"><?php echo $checkStr; ?></span> | <span><?php echo $updateStr; ?></span> | <span class="nb"><?php echo $delStr; ?></span></td>
    </tr>

	<?php

	}
	$stoptimer = microtime(true);
	?>
 <?php

//判断无记录样式
if($dosql->GetTotalRow() == 0)
{
	echo '<tr><td align="center" colspan="8">暂无记录</td></tr>';
}
?>
  </table>

</div>
<!--/列表-->

<!--内容底部-->
<div class="line20"></div>
<div class="pagelist">

  <?php echo $dopage->GetList($sql,$checkPagenum); ?>
  <div class="l-btns"><span>
<?php 

$timer = $stoptimer-$starttimer;
echo " $timer s";?></span>
</div>
</div>
<!--/内容底部-->
</form>
</body>
</html>
